home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-04-21 | 9.7 KB | 320 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: GrfxRun.cpp
- // Release Version: $ 1.0d1 $
- //
- // Author: Anthone Burbidge
- // Creation Date: 3/28/94
- //
- // Copyright: © 1993, 1994 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef _GRFXRUN_
- #include "GrfxRun.h"
- #endif
-
- #if !defined(__EXCEPTIONS__) && defined(qUniversalHeaders)
- #include <Exceptions.h>
- #undef resumeLabel
- #define resumeLabel(exception)
- #endif
-
- #pragma segment TextPart
-
- //========================================================================================
- // CLASS CBetterGraphicsRun
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CBetterGraphicsRun::CBetterGraphicsRun
- //----------------------------------------------------------------------------------------
-
- CBetterGraphicsRun::CBetterGraphicsRun() :
- fExtraWidth(0),
- fSelectionWidth(0)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CBetterGraphicsRun::~CBetterGraphicsRun
- //----------------------------------------------------------------------------------------
-
- CBetterGraphicsRun::~CBetterGraphicsRun()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CBetterGraphicsRun::InitBetterGraphicsRun
- //----------------------------------------------------------------------------------------
-
- void CBetterGraphicsRun::InitBetterGraphicsRun(short selectionWidth)
- {
- this->IRunObject();
- fSelectionWidth = selectionWidth;
- }
-
- //----------------------------------------------------------------------------------------
- // CBetterGraphicsRun::GetObjFlags
- //----------------------------------------------------------------------------------------
-
- TObjFlags CBetterGraphicsRun::GetObjFlags()
- {
- return CRunObject::GetObjFlags() | kIndivisibleRun | kFixedRangeRun | kHasCustomHilite;
- }
-
- //----------------------------------------------------------------------------------------
- // CBetterGraphicsRun::IsTextRun
- //----------------------------------------------------------------------------------------
-
- Boolean CBetterGraphicsRun::IsTextRun() const
- {
- return false;
- }
-
- //----------------------------------------------------------------------------------------
- // CBetterGraphicsRun::SetSelectionWidth
- //----------------------------------------------------------------------------------------
-
- void CBetterGraphicsRun::SetSelectionWidth(short selectionWidth)
- {
- fSelectionWidth = selectionWidth;
- }
-
- //----------------------------------------------------------------------------------------
- // CBetterGraphicsRun::GetScaledDimensions
- //----------------------------------------------------------------------------------------
-
- #ifdef txtnScal
- void CBetterGraphicsRun::GetScaledDimensions(short* hite, short* width,
- const Point* numer/*=nil*/,
- const Point* denom/*=nil*/)
- #else
- void CBetterGraphicsRun::GetScaledDimensions(short* hite, short* width)
- #endif
- {
- if (!this->GetDimensions(hite, width)) {
- *hite = kDefaultHite;
- *width = kDefaultWidth;
- }
-
- check(fExtraWidth <= 0);
- *width += fExtraWidth;
-
- #ifdef txtnScal
- Point adjNumer, adjDenom;
- if (numer) {
- adjNumer = *numer;
- adjDenom = *denom;
- }
- else {adjNumer.h = adjNumer.v = adjDenom.h = adjDenom.v = 1;}
-
- this->AdjustScaleVals(&adjNumer, &adjDenom);
-
- *hite = ScaleVal(*hite, adjNumer.v, adjDenom.v) + 2 * GetSelectionWidth();
- *width = ScaleVal(*width, adjNumer.h, adjDenom.h) + 2 * GetSelectionWidth();
- #else
- *hite += 2 * GetSelectionWidth();
- *width += 2 * GetSelectionWidth();
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // CBetterGraphicsRun::CalcHiteInfo
- //----------------------------------------------------------------------------------------
-
- void CBetterGraphicsRun::CalcHiteInfo(short* ascent, short* descent, short* leading)
- {
- short hite, width;
- if (!this->GetDimensions(&hite, &width)) {hite = kDefaultHite;}
-
- *ascent = hite + 2 * GetSelectionWidth();
- *descent = 0;
- *leading = 0;
- }
-
- //----------------------------------------------------------------------------------------
- // CBetterGraphicsRun::AdjustObjRect
- //----------------------------------------------------------------------------------------
-
- #ifdef txtnScal
- void CBetterGraphicsRun::AdjustObjRect(Rect* objRect, Point numer, Point denom)
- #else
- void CBetterGraphicsRun::AdjustObjRect(Rect* objRect)
- #endif
- {
- short hite, width;
-
- #ifdef txtnScal
- this->GetScaledDimensions(&hite, &width, &numer, &denom);
- #else
- this->GetScaledDimensions(&hite, &width);
- #endif
-
- short vMargin = RectHite(*objRect) - hite;
-
- objRect->top += vMargin;
- objRect->bottom = objRect->top + hite;
-
- InsetRect(objRect, GetSelectionWidth(), GetSelectionWidth());
- }
-
- //----------------------------------------------------------------------------------------
- // CBetterGraphicsRun::GetObjectRect
- //----------------------------------------------------------------------------------------
-
- void CBetterGraphicsRun::GetObjectRect(const RunPositionPB* paramPb, Rect* objRect)
- {
- objRect->top = paramPb->runLineTop;
- objRect->bottom = objRect->top+paramPb->runLineHite;
- objRect->left = paramPb->runLeftEdge;
- objRect->right = objRect->left+paramPb->runTotalWidth;
-
- #ifdef txtnScal
- this->AdjustObjRect(objRect, paramPb->numer, paramPb->denom);
- #else
- this->AdjustObjRect(objRect);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // CBetterGraphicsRun::DoDrawJust
- //----------------------------------------------------------------------------------------
-
- void CBetterGraphicsRun::DoDrawJust(DrawJustPb* paramPb)
- {
- Rect objRect = *(paramPb->lineRectPtr);
-
- objRect.left = FixRound(paramPb->runLeftEdge);
- TLineRunPtr runPtr = paramPb->runInfo;
- objRect.right = objRect.left+FixRound(runPtr->runWidth + runPtr->runExtraWidth);
-
- #ifdef txtnScal
- this->AdjustObjRect(&objRect, paramPb->numer, paramPb->denom);
- #else
- this->AdjustObjRect(&objRect);
- #endif
-
- this->Draw(&objRect);
- }
-
- //----------------------------------------------------------------------------------------
- // CBetterGraphicsRun::DoPixel2Char
- //----------------------------------------------------------------------------------------
-
- void CBetterGraphicsRun::DoPixel2Char(Pixel2CharPb* paramPb)
- {
- IndivisiblePixel2Char(paramPb);
- }
-
- //----------------------------------------------------------------------------------------
- // CBetterGraphicsRun::DoChar2Pixel
- //----------------------------------------------------------------------------------------
-
- short CBetterGraphicsRun::DoChar2Pixel(Char2PixelPb* paramPb)
- {
- return IndivisibleChar2Pixel(paramPb);
- }
-
- //----------------------------------------------------------------------------------------
- // CBetterGraphicsRun::SetHilite
- //----------------------------------------------------------------------------------------
-
- void CBetterGraphicsRun::SetHilite(char oldHilite, char newHilite,
- const RunPositionPB* paramPb,
- Boolean doDraw)
- {
- if (doDraw)
- {
- this->DrawSelection(oldHilite, paramPb);
- this->DrawSelection(newHilite, paramPb);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CBetterGraphicsRun::DoMeasure
- //----------------------------------------------------------------------------------------
-
- Fixed CBetterGraphicsRun::DoMeasure(MeasurePb* paramPb)
- {
- short hite, width;
- #ifdef txtnScal
- this->GetScaledDimensions(&hite, &width, ¶mPb->numer, ¶mPb->denom);
- #else
- this->GetScaledDimensions(&hite, &width);
- #endif
-
- return width << 16;
- }
-
- //----------------------------------------------------------------------------------------
- // CBetterGraphicsRun::DoBreak
- //----------------------------------------------------------------------------------------
-
- StyledLineBreakCode CBetterGraphicsRun::DoBreak(LineBreakPb* paramPb)
- {
- fExtraWidth = 0;
-
- short hite, width;
- this->GetScaledDimensions(&hite, &width);
-
- *(paramPb->widthAvail) -= (width << 16);
-
- Boolean lineStart = (paramPb->breakOffset != 0);
- paramPb->breakOffset = paramPb->breakStartOffset;
-
- StyledLineBreakCode result;
- if (*(paramPb->widthAvail) < 0) {
- if (lineStart) {//the line < object width ==> force break
- result = smBreakChar;
- paramPb->breakOffset += paramPb->breakLen;
-
- TX_DebugMessage((ConstStr255Param)"\p obj can no fit, decrease obj width");
-
- fExtraWidth = short(*paramPb->widthAvail >> 16); //-ive
- }
- else {result = smBreakWord;} //break before the object
- }
- else {
- paramPb->breakOffset += paramPb->breakLen;
- result = (*(paramPb->widthAvail)) ? smBreakOverflow : smBreakWord;
- }
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // CBetterGraphicsRun::DrawSelection
- //----------------------------------------------------------------------------------------
-
- void CBetterGraphicsRun::DrawSelection(char hiliteStat, const RunPositionPB* paramPb)
- {
- if (hiliteStat == kSelOff) {return;}
-
- Rect objRect;
- this->GetObjectRect(paramPb, &objRect);
- InsetRect(&objRect, -GetSelectionWidth(), -GetSelectionWidth());
-
- PenState savedPen;
- GetPenState(&savedPen);
-
- PenMode(patXor);
-
- ConstPatternParam pat = (hiliteStat == kSelInactiv) ? &ASLMQDGlobals.gray : &ASLMQDGlobals.black;
- PenPat(pat);
-
- FrameRect(&objRect);
-
- SetPenState(&savedPen);
- }
-
- //----------------------------------------------------------------------------------------
- // CBetterGraphicsRun::SetCursor
- //----------------------------------------------------------------------------------------
-
- void CBetterGraphicsRun::SetCursor(Point, const RunPositionPB*) const
- {
- ::SetCursor(&ASLMQDGlobals.arrow);
- }
-
-